#!/bin/bash
USER="$1"
HOST="$2"

die(){
  printf -- "$(tput setaf 1)$*$(tput sgr0)\n"
  exit 1
}

hi(){
  printf -- "$(tput setaf 3)$*$(tput sgr0)\n"
}

[[ $USER ]] && [[ $HOST ]] || die "usage: $0 <user> <host>"

forward_schema(){
local qt=$1
cat <<EOF
{
  "body": {
    "action": "finger",
    "input": {
      "host": "$HOST",
      "user": "$USER"
    },
    "connection": null,
    "meta": {}
  },
  "version": "v1",
  "type": "action_start"
}
EOF
}

hi "- Testing Finger"
forward_schema | docker run -i --rm  komand/finger --debug run | jq '.' || die "Docker failed"
printf "\n"
